package com.abigdreamer.dicux;

import java.io.IOException;
import java.util.Map;

import com.abigdreamer.newspider.HtmlSpider;
import com.abigdreamer.newspider.LoginFormInfo;
import com.abigdreamer.newspider.ThreadTaskProcesser;
import com.abigdreamer.newspider.UrlExtractor;

/**
 * 
 * @author Darkness
 * @date 2013-6-1 下午08:19:52
 * @website http://www.abigdreamer.com
 * @version V1.0
 */
public class ArticleUrlExtractorProcesser extends ThreadTaskProcesser<ArticleUrlExtractor> {

	HtmlSpider spider = new HtmlSpider();
	String host;

	public ArticleUrlExtractorProcesser(ArticleUrlExtractor spiderManager, LoginFormInfo loginFormInfo, String host) {
		super(spiderManager);
		this.host = host;
		try {
			spider.login(loginFormInfo, false);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void doTask(Object task) {
		String url = task + "";

		String html = "";
		try {
			html = spider.get(url);
		} catch (IOException e) {
			System.out.println("url:" + url + " 抓取失败，稍后重试");
		}

		// 文章url
		Map<String, String> articleurls = UrlExtractor.getHtmlURL(html, "thread-(\\d+)-(\\d+)-(\\d+).html", "[class=xst]", host);
		getThreadTaskManager().addArticleUrls(articleurls, url);
	}

}
